package com.yenlien.traceyun.usercenter.bean;

import com.yenlien.traceyun.usercenter.entity.App;
import com.yenlien.traceyun.usercenter.entity.Resource;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-03-10
 * @description:
 **/
public class MenuTree {

    private String id;
    private String name;
    private String url;
    private String router;
    private boolean configMenu;
    private String parentId;
    private String icon;
    private int orderList;
    private String label;
    private String appId;
    private String appName;
    private String appUrl;
    private List<MenuTree> children;
    private String type;
    private int sortNum;
    private boolean checked;
    private boolean appStatus;
    private String appCode;
    private String tibetName;


    public MenuTree() {

    }

    public MenuTree(Resource menu, String appName, String appId, boolean status, String appUrl, String appCode) {
        this.setId(menu.getId());
        this.setName(menu.getName());
        this.setUrl(menu.getUrl());
        this.setConfigMenu(menu.isConfigMenu());
        this.setParentId(menu.getParentId());
        this.setIcon(menu.getIcon());
        this.setLabel(menu.getName());
        this.setOrderList(menu.getSortNum());
        this.setRouter(menu.getRouter());
        this.setType(menu.getType().name());
        this.setSortNum(menu.getSortNum());
        this.setTibetName(menu.getTibetName());
        this.setAppId(appId);
        this.setAppUrl(appUrl);
        this.setAppName(appName);
        this.appStatus = status;
        this.appCode = appCode;
    }

    public static MenuTree create(Resource menu) {
        MenuTree mt = new MenuTree();
        mt.setId(menu.getId());
        mt.setName(menu.getName());
        mt.setUrl(menu.getUrl());
        mt.setParentId(menu.getParentId());
        mt.setIcon(menu.getIcon());
        mt.setLabel(menu.getName());
        mt.setOrderList(menu.getSortNum());
        mt.setRouter(menu.getRouter());
        mt.setType(menu.getType().name());
        mt.setSortNum(menu.getSortNum());
        mt.setAppId(menu.getAppId());
        mt.setConfigMenu(menu.isConfigMenu());
        mt.setTibetName(menu.getTibetName());
        return mt;
    }

    public static MenuTree create(Resource menu, App app) {
        MenuTree mt = new MenuTree();
        mt.setId(menu.getId());
        mt.setName(menu.getName());
        mt.setUrl(menu.getUrl());
        mt.setParentId(menu.getParentId());
        mt.setIcon(menu.getIcon());
        mt.setLabel(menu.getName());
        mt.setOrderList(menu.getSortNum());
        mt.setRouter(menu.getRouter());
        mt.setType(menu.getType().name());
        mt.setSortNum(menu.getSortNum());
        mt.setAppId(menu.getAppId());
        mt.setConfigMenu(menu.isConfigMenu());
        mt.setTibetName(menu.getTibetName());
        mt.setAppId(app.getId());
        mt.setAppUrl(app.getUrl());
        mt.setAppName(app.getName());
        mt.setAppStatus(app.isUsed());
        mt.setAppCode(app.getCode());
        return mt;
    }

    public String getTibetName() {
        return tibetName;
    }

    public void setTibetName(String tibetName) {
        this.tibetName = tibetName;
    }

    public static List<MenuTree> create(List<Resource> menus) {
        List<MenuTree> mts = new ArrayList<>();
        if (menus != null && menus.size() > 0) {
            for (Resource menu : menus) {
                mts.add(create(menu));
            }
        }
        return mts;
    }

    public static List<MenuTree> create(List<Resource> menus, App app) {
        List<MenuTree> mts = new ArrayList<>();
        if (menus != null && menus.size() > 0) {
            for (Resource menu : menus) {
                mts.add(create(menu, app));
            }
        }
        return mts;
    }

    public void setApp(App app) {
        this.setAppUrl(app.getUrl());
        this.setAppName(app.getName());
        this.setAppStatus(app.isUsed());
        this.setAppCode(app.getCode());
    }

    public boolean isConfigMenu() {
        return configMenu;
    }

    public void setConfigMenu(boolean configMenu) {
        this.configMenu = configMenu;
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public int getOrderList() {
        return orderList;
    }

    public void setOrderList(int orderList) {
        this.orderList = orderList;
    }

    public List<MenuTree> getChildren() {
        return children;
    }

    public void setChildren(List<MenuTree> children) {
        this.children = children;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getRouter() {
        return router;
    }

    public void setRouter(String router) {
        this.router = router;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getSortNum() {
        return sortNum;
    }

    public void setSortNum(int sortNum) {
        this.sortNum = sortNum;
    }

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }

    public boolean isAppStatus() {
        return appStatus;
    }

    public void setAppStatus(boolean appStatus) {
        this.appStatus = appStatus;
    }

    public String getAppUrl() {
        return appUrl;
    }

    public void setAppUrl(String appUrl) {
        this.appUrl = appUrl;
    }

    public String getAppCode() {
        return appCode;
    }

    public void setAppCode(String appCode) {
        this.appCode = appCode;
    }

    @Override
    public String toString() {
        return "MenuTree{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", url='" + url + '\'' +
                ", router='" + router + '\'' +
                ", parentId='" + parentId + '\'' +
                ", icon='" + icon + '\'' +
                ", orderList=" + orderList +
                ", label='" + label + '\'' +
                ", appId='" + appId + '\'' +
                ", appName='" + appName + '\'' +
                ", children=" + children +
                ", type='" + type + '\'' +
                ", sortNum=" + sortNum +
                '}';
    }
}
